package com.ruoyi.web.controller.business;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.*;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.BUser;
import com.ruoyi.system.domain.vo.BUserVo;
import com.ruoyi.system.service.BUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;

/**
 * 医生管理
 * @author yangxz
 **/
@RestController
@RequestMapping("/business/doctor")
public class DoctorController extends BaseController {

    @Autowired
    BUserService userService;

    /**
     * 获取医生列表
     */
//    @PreAuthorize("@ss.hasPermi('dict:doctor:list')")
    @PreAuthorize("@ss.hasRole('qygl')")
    @GetMapping("/list")
    public TableDataInfo list(BUser buser)
    {
        startPage();
        List<BUserVo> list = userService.selectUserList(buser);
        return getDataTable(list);
    }

    /**
     * 根据医生Id获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('dict:doctor:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable Long userId) {
        BUserVo userVo = userService.selectUserById(userId);
        return success(userVo);
    }

    /**
     * 修改医生
     */
    @PreAuthorize("@ss.hasPermi('dict:doctor:edit')")
    @Log(title = "修改医生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BUser buser){
        buser.setUpdateBy(SecurityUtils.getUsername());
        buser.setUpdateTime(new Date());
        return toAjax(userService.updateById(buser));
    }

    /**
     * 删除医生
     */
    @PreAuthorize("@ss.hasPermi('dict:doctor:remove')")
    @Log(title = "删除文章", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(userService.deleteUserByIds(userIds));
    }
}
